package com.ying.tests.AAAmode.singleton;

public class HungrySingletonTest {

    public static void main(String[] args) {
        HungrySingletonService instance = HungrySingletonService.getInstance();
        instance.getFood();
        HungrySingletonService instance2 = HungrySingletonService.getInstance();
        instance2.getFood();
        // 比较地址，是否是同一个实例
        if (instance == instance2) {
            System.out.println("同一个实例");
        } else {
            System.out.println("不同的实例");
        }
    }

}

class HungrySingletonService {

    private static HungrySingletonService instance = new HungrySingletonService();

    private HungrySingletonService() {
        System.out.println("饿了就吃点东西吧");
    }

    public void getFood() {
        System.out.println("吃了一个🍭");
    }

    public static HungrySingletonService getInstance() {
        return instance;
    }
}
